package com.gmrz.uap.operlog;

import com.gmrz.uap.cfg.SystemConst;
import com.gmrz.uap.common.ConditionConst;
import com.gmrz.uap.common.ControllerSupport;
import com.gmrz.uap.model.OperLog;
import com.gmrz.uap.resource.ResourceInterceptor;
import com.jfinal.aop.Before;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.render.JsonRender;

public class OperLogController  extends ControllerSupport {

    @Before(ResourceInterceptor.class)
    public void index() {
    }

    /**
     * 根据前台发过来的参数进行查询，可以进行分页，排序
     */
    public void list() {

        int page = getParaToInt(SystemConst.DATATABLE_PAGINATE_OFFSET, SystemConst.DATATABLE_PAGINATE_OFFSET_DEFAULT);
        int rows = getParaToInt(SystemConst.DATATABLE_PAGINATE_LIMIT, SystemConst.DATATABLE_PAGINATE_LIMIT_DEFAULT);

        String sort = getPara(SystemConst.DATATABLE_PAGINATE_SORT, SystemConst.DEFAULT_ORDERBY_CREATETS);
        String order = getPara(SystemConst.DATATABLE_PAGINATE_ORDER, SystemConst.DATATABLE_PAGINATE_ORDER_DEFAULT);

        OperLog operLog = getModel(OperLog.class);

        String startCreatets = getPara(ConditionConst.STARTCREATETS);
        if (!StrKit.isBlank(startCreatets)) {
            condition.put(ConditionConst.STARTCREATETS, startCreatets);
        }

        String endCreatets = getPara(ConditionConst.ENDCREATETS);
        if (!StrKit.isBlank(endCreatets)) {
            condition.put(ConditionConst.ENDCREATETS, endCreatets);
        }

            Page<OperLog> descPage = OperLogService.me.findOperLogListForPaginate(operLog, page, rows, sort, order, condition);

        result.put(SystemConst.DATATABLE_PAGINATE_TOTAL, descPage.getTotalRow());
        result.put(SystemConst.DATATABLE_PAGINATE_ROWS, descPage.getList());

        render(responseJsonRender(result));
    }
}
